package com.example.mynetwork2.mvpdesign.view;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.mynetwork2.R;
import com.example.mynetwork2.login.utils.Utils;
import com.example.mynetwork2.mvpdesign.presenter.CidianPresenter;
import com.example.mynetwork2.mvpdesign.view.iview.IFanyiView;

public class FanyiAct extends AppCompatActivity implements IFanyiView {
    private EditText et;
    private TextView tv;
    CidianPresenter cidianPresenter;  // 声明了Presenter对应类
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mvp_indexactivity_layout);
        init();
    }

    @Override
    public void init() {

        et = (EditText) findViewById(R.id.input_word_et);
        tv = (TextView) findViewById(R.id.fanyi_tv);
        Button fanyi_bt = findViewById(R.id.fanyi_bt);
        cidianPresenter = new CidianPresenter(this);
        fanyi_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String input = et.getText().toString();
                if (!Utils.isEmpty(input)){
                         cidianPresenter.inputToModel(input);
                }
            }
        });

    }

    @Override
    public void setInfo(String str) {
        //主线程
        this.runOnUiThread(()->{
            tv.setText(str);
        });

    }

    @Override
    public void setError() {
        //主线程
        this.runOnUiThread(()->{
            tv.setText("错误");
        });
    }
}
